import { createMemoryHistory, createRouter } from "vue-router";

import HomeView from "../view/HomeView.vue";

const routes = [
  {
    path: "/",
    component: HomeView,
    children: [
      { path: "/about", component: () => import("../view/AboutView.vue") },
      { path: "/blog", component: () => import("../view/BlogView.vue") },
      { path: "/img", component: () => import("../view/ImgView.vue") },
      { path: "/link", component: () => import("../view/LinkView.vue") },
      { path: "/food", component: () => import("../view/FoodView.vue") },
      { path: "/video", component: () => import("../view/VideoView.vue") },
      { path: "/music", component: () => import("../view/MusicView.vue") },
      { path: "/manage", component: () => import("../view/ManageView.vue") },
      { path: "/welcome", component: () => import("../view/WelComeView.vue") },
    ],
  },
];

export const router = createRouter({
  history: createMemoryHistory(),
  routes,
});

router.beforeEach((to, from) => {
  // console.log(from.path, " => ", to.path);
  // ...
  // 返回 false 以取消导航
  return true;
});

export const gourl = (url: any) => {
  router.push(url);
};
